package com.example.demo.tests;

import com.example.demo.common.Utils;
import org.openqa.selenium.By;

public class LoginPage extends Utils {
    public static String url = "http://82.157.143.27:8081/sign-in.html";

    public LoginPage() {
        super(url);
    }

    //检查登录功能
    public void login() throws InterruptedException {
        driver.findElement(By.cssSelector("#username")).sendKeys("1");
        driver.findElement(By.cssSelector("#password")).sendKeys("1");

        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(2000);

        //检查登录后有没有"发布帖子按钮"
       // driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post" ));

        //页面标签检查是否登录成功
       // String ex = driver.getTitle();
      //  assert ex.equals("论坛交流平台");

       /* //退出登录
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();

        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#index_user_logout")).click();*/

    }

    //检查注册功能
    public void register(){
        //跳转注册页面
        driver.findElement(By.cssSelector("body > div > div:nth-child(2) > a")).click();

        driver.findElement(By.cssSelector("#username")).sendKeys("2");
        driver.findElement(By.cssSelector("#nickname")).sendKeys("2");
        driver.findElement(By.cssSelector("#password")).sendKeys("2");
        driver.findElement(By.cssSelector("#passwordRepeat")).sendKeys("2");

        //同意条款
        driver.findElement(By.cssSelector("#policy")).click();

        //注册
        driver.findElement(By.cssSelector("#submit")).click();

        driver.navigate().back();
    }

}

